//
//  FunctionTest.swift
//  第一个swift
//
//  Created by zhangjianyun on 17/6/22.
//  Copyright © 2017年 com.taihejiacheng. All rights reserved.
//

import Foundation

func testContant(_ v1:String, _ v2:String) -> String {
    return v1 + v2
}

func contant2(_ v1:String, andValue:String) -> String {
    return v1+" and "+andValue
}

func getInfo() -> (String, String, String) {
     return ("hello", " all ", "world")
}

func testFunctionIntestFunction() -> Int {
    var y = 10
    
    func add() {
        y = y+5
    }
    add()
    return y
    
}

func getFuncPoint() -> ((Int) -> Int) {
    func addOne(num:Int)-> Int {
        return num+1
    }
    return addOne
}

func textFunction() {
    
    let v = testContant("hello","world")
    let v1 = contant2("hello", andValue: "world")
    
    print("test Function" + v)
    print("contant function " + v1)
    
    let (v3,v4,v5) = getInfo()
    print(v3+v4+v5)
    
    let v6 = testFunctionIntestFunction()
    print("v6 = \(v6)" )
    
    //函数指针
    let functionPoint = getFuncPoint()
    let v7 = functionPoint(199)
    print("v7 = \(v7)")
   
    let v8 = hasMatch(list:scoreArr, function: lessThanTen)
    print("v8 is \(v8)")
}

func hasMatch(list: [Int], function: (Int)->Bool) -> Bool {
    for item in list {
        if function(item) {
            return true
        }
    }
    return false
}

func lessThanTen(number:Int) -> Bool {
    return number<=10
}




func hasClosure(arr:[Int],value:Int, cb:(_ num:Int) -> Bool) -> Bool {
    for item in arr {
        if cb(item) {
            return true
        }
    }
    return false
}


var arr9 = [20,9,100,34,89,43]

//类似block
//找arr里边是否有比40大的数
var v9 = hasClosure(arr: arr9,value: 40,cb: {
    (num: Int)-> Bool in
    return num>=40
});


















